{% extends "base.html" %}

{% block content %}
<h2>🛒 购物车</h2>
{% if cart_items %}
    <div class="table-responsive">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>商品</th>
                    <th>单价</th>
                    <th>数量</th>
                    <th>小计</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for item in cart_items %}
                    <tr>
                        <td>{{ item.product.name }}</td>
                        <td>¥{{ item.product.price }}</td>
                        <td>{{ item.quantity }}</td>
                        <td>¥{{ item.item_total }}</td>
                        <td>
                            <a href="{{ url_for('remove_from_cart', product_id=item.product.id) }}" 
                               class="btn btn-sm btn-outline-danger">移除</a>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="3" class="text-end"><strong>总计：</strong></td>
                    <td><strong>¥{{ total }}</strong></td>
                    <td></td>
                </tr>
            </tfoot>
        </table>
    </div>
    {% if current_user.is_authenticated %}
        <form method="POST" action="{{ url_for('checkout') }}">
            <button type="submit" class="btn btn-success btn-lg">✅ 立即下单</button>
        </form>
    {% else %}
        <div class="alert alert-info">
            请先<a href="{{ url_for('login') }}">登录</a>再下单
        </div>
    {% endif %}
{% else %}
    <div class="text-center py-5">
        <p class="h4">购物车是空的 😔</p>
        <a href="{{ url_for('index') }}" class="btn btn-primary">去逛逛</a>
    </div>
{% endif %}
{% endblock %}